const state = {
  impedanceL: [], // 左脑阻抗数组
  impedanceR: [], // 右脑阻抗数组
  impedanceAll: [], // 全脑阻抗数组
  isMonitoring: false, // 监测状态
  isFirstDetection: true, // 是否首次检测
}

const mutations = {
  SET_IMPEDANCE_L(state, value) {
    state.impedanceL = value
  },
  SET_IMPEDANCE_R(state, value) {
    state.impedanceR = value
  },
  SET_IMPEDANCE_ALL(state, value) {
    state.impedanceAll = value
  },
  SET_IS_MONITORING(state, value) {
    state.isMonitoring = value
  },
  SET_IS_FIRST_DETECTION(state, value) {
    state.isFirstDetection = value
  },
  CLEAR_IMPEDANCE_DATA(state) {
    state.impedanceL = []
    state.impedanceR = []
    state.impedanceAll = []
  }
}

const actions = {
  updateImpedanceData({ commit }, { leftValue, rightValue }) {
    const average = (leftValue + rightValue) / 2
    commit('SET_IMPEDANCE_L', [...state.impedanceL, leftValue])
    commit('SET_IMPEDANCE_R', [...state.impedanceR, rightValue])
    commit('SET_IMPEDANCE_ALL', [...state.impedanceAll, average])
  },
  clearMonitoringData({ commit }) {
    commit('CLEAR_IMPEDANCE_DATA')
    commit('SET_IS_FIRST_DETECTION', true)
    commit('SET_IS_MONITORING', false)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
} 